package com.ling.pl.security.dao;

import com.ling.pl.core.commons.constant.TableColnumDef;
import com.ling.pl.core.commons.support.DaoPage;
import com.ling.pl.core.commons.utils.AssertHelper;
import com.ling.pl.core.dao.impl.BaseDao;
import com.ling.pl.security.model.DefaultUser;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * @author bo.wang
 */
public class BaseDefaultUserDao extends BaseDao {

    public static final String BEAN_ID = "defaultUserDao";

    protected void buildDefaultUserQuery(StringBuffer query, Map values, Map params) {
        query.append(" from DefaultUser where 1=1 ");
        Object value = params.get("flag");
        if (AssertHelper.notEmpty(value)) {
            query.append(" and flag=:flag");
            values.put("flag", value);
        } else {
            query.append(" and flag=:flag");
            values.put("flag", TableColnumDef.FLAG_EFFECT);
        }
        if (AssertHelper.notEmpty(TableColnumDef.FILTER_NAME_PATTERN)) {
            //			query.append(" and status=:status");
            //			values.put("status", value);
        }
    }

    public DaoPage findDefaultUserByParams(Map params, Integer pageIndex, Integer pageSize) {
        StringBuffer query = new StringBuffer();
        Map values = new HashMap();
        buildDefaultUserQuery(query, values, params);
        return pageBy(query, values, pageIndex, pageSize);
    }

    public List<DefaultUser> findDefaultUserByParams(Map params) {
        StringBuffer query = new StringBuffer();
        Map values = new HashMap();
        buildDefaultUserQuery(query, values, params);
        return findBy(query, values);
    }
}

